﻿#include "FITKAcousticsDiscNodeList.h"
#include <QMutexLocker>
#include <QMutex>

namespace Acoustics
{
    void DiscNode::setNodeSource(DiscNodeSourceType::DiscNodeSource s)
    {
        _source = s;
    }

    DiscNodeSourceType::DiscNodeSource DiscNode::getNodeSource()
    {
        return _source;
    }

    void DiscNode::setSourceID(const int& id)
    {
        _sourceID = id;
    }


    int DiscNode::getSourceID()
    {
        return _sourceID;
    }

    void DiscNode::setSourceNodeID(const int& id)
    {
        _sourceNodeID = id;
    }

    int DiscNode::getSourceNodeID()
    {
        return _sourceNodeID;
    }

   
    void FITKAcousticsDiscNodeList::getAllNodeID(QList<int>& idlist)
    {
        QMutexLocker locker(&_mutex);

        for (Core::FITKNode* node : _nodeList)
        {
            if (node == nullptr) continue;
            idlist.append(node->getNodeID());
        }

    }

    int FITKAcousticsDiscNodeList::addNode(const double x, const double y, const double z)
    {
        QMutexLocker locker(&_mutex);
        //创建节点
        Acoustics::DiscNode* node = new Acoustics::DiscNode;
        node->setCoor(x, y, z);
        _nodeList.append(node);
        //获取索引与ID，形成映射关系
        const int index = _nodeList.size() - 1;
        const int id = ++_nodeMaxID;
        node->setNodeID(id);
        _idIndexMap.insert(id, index);
        return id;
    }

    void FITKAcousticsDiscNodeList::addNode(const int id, const double x, const double y, const double z)
    {
        QMutexLocker locker(&_mutex);
        //创建对象
        Core::FITKNode* node = new Acoustics::DiscNode(id, x, y, z);
        _nodeList.append(node);
        //获取索引与ID，形成映射关系
        const int index = _nodeList.size() - 1;
        _idIndexMap.insert(id, index);
        //静态变量增大
        _nodeMaxID = _nodeMaxID >= id ? _nodeMaxID : id;
    }

    Acoustics::DiscNode* FITKAcousticsDiscNodeList::addDiscNode(const double x, const double y, const double z)
    {
        QMutexLocker locker(&_mutex);
        //创建节点
        Acoustics::DiscNode* node = new Acoustics::DiscNode;
        node->setCoor(x, y, z);
        _nodeList.append(node);
        //获取索引与ID，形成映射关系
        const int index = _nodeList.size() - 1;
        const int id = ++_nodeMaxID;
        node->setNodeID(id);
        _idIndexMap.insert(id, index);
        return node;
    }

}



